package com.pptree.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
 * Servlet3.0支持使用注解配置Servlet。我们只需在Servlet对应的类上使用@WebServlet进行标注， 
 * 我们就可以访问到该Servlet了，而不需要再在web.xml文件中进行配置。@WebServlet的urlPatterns 
 * 和value属性都可以用来表示Servlet的部署路径，它们都是对应的一个数组。 
 * @WebServlet(urlPatterns = {"/simple"},initParams = {@WebInitParam(name = "username", value = "tom")} 
 * */
@WebServlet(urlPatterns={"/login"})
public class LoginServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		PrintWriter pw = response.getWriter();
		pw.write("<!DOCTYPE html>");
		pw.write("<html>");
		pw.write("<head>");
		pw.write("<meta charset=\"utf-8\" />");
		pw.write("</head>");
		pw.write("<body>");
		pw.write("<h1>你好，欢迎来到Servlet世界</h1>");
		pw.write("<h1>请求的方法："+request.getMethod()+"</h1>");
		pw.write("<h1>上下文路径："+request.getContextPath()+"</h1>");
		pw.write("</body>");
		pw.write("</html>");
		
		pw.flush();
		pw.close();
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
